window.layModules = {};
window.TopMenuHandler = {
    logout: function () {
        $.post('/front/user/_logout', function (res) {
            if (res.code === 0) {
                window.location.href = '/';
            } else {
                alert(res.msg);
            }
        }, 'json');
    }
};
$(function () {
    function onLoad() {
        var userTopMenu = $('#user-top-menu');
        console.log(userTopMenu);
        if (userTopMenu.length > 0) {
            $.get('/front/user/current', function (res) {
                if (res.code === 0) {
                    var user = res.data;
                    var html = layModules.laytpl($('#user-menu-template').html()).render(user);
                    userTopMenu.html(html);
                    layModules.element.render();
                } else {
                    alert(res.msg);
                }
            }, 'json');
        }
    }

    layui.use(['laytpl', 'element'], function () {
        layModules.laytpl = layui.laytpl;
        layModules.element = layui.element;
        onLoad();
    });
});